package com.art8173.advanced.day1.test3;
/**
 * 银行卡类 - 主卡和副卡的父类
 * 注意：余额(balance)现在代表主账户的余额。
 */
public class BankCard {
    protected String cardNumber;
    protected String accountHolder;
    // 注意：这个 balance 现在代表主账户的余额
    // 副卡操作的是同一个主账户余额
    protected double balance;

    public BankCard() {
    }

    public BankCard(String cardNumber, String accountHolder, double balance) {
        this.cardNumber = cardNumber;
        this.accountHolder = accountHolder;
        this.balance = balance;
    }

    // getter 和 setter 方法 (省略 setter for balance for safety, use deposit/withdraw)
    public String getCardNumber() { return cardNumber; }
    public void setCardNumber(String cardNumber) { this.cardNumber = cardNumber; }

    public String getAccountHolder() { return accountHolder; }
    public void setAccountHolder(String accountHolder) { this.accountHolder = accountHolder; }

    public double getBalance() { return balance; }
    // 通常不直接暴露 setBalance，通过业务方法控制

    // 存款方法 (主卡和副卡都可用，增加主账户余额)
    public void deposit(double amount) {
        if (amount > 0) {
            balance += amount;
            System.out.println("[" + accountHolder + "] 存款成功！存入金额: " + amount + "元。主账户当前余额: " + balance + "元。");
        } else {
            System.out.println("[" + accountHolder + "] 存款金额必须大于0！");
        }
    }

    // 取款方法 (在父类中定义基础扣款逻辑)
    // 这个方法负责从主账户余额扣款，检查余额是否足够（不考虑透支）
    protected boolean deductBalance(double amount) {
        if (amount <= 0) {
            System.out.println("[" + accountHolder + "] 取款金额必须大于0！");
            return false;
        }
        if (amount > balance) {
            System.out.println("[" + accountHolder + "] 余额不足！主账户余额: " + balance + "元，取款金额: " + amount + "元。");
            return false;
        } else {
            balance -= amount;
            System.out.println("[" + accountHolder + "] 扣款成功！扣除金额: " + amount + "元。主账户当前余额: " + balance + "元。");
            return true;
        }
    }

    // 显示卡信息
    public void displayInfo() {
        System.out.println("卡号: " + cardNumber + ", 户主: " + accountHolder);
    }
}